package com.ruoyi.culture.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.culture.domain.Classification;
import com.ruoyi.culture.domain.CreativePublish;
import com.ruoyi.culture.domain.CultureMeet;
import com.ruoyi.culture.domain.Label;
import com.ruoyi.culture.service.ClassificationService;
import com.ruoyi.culture.service.CreativePublishService;
import com.ruoyi.culture.service.LabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/creativeWork")
@Api(tags = {"文创作品在线发布控制器"})
public class CreativeWorkController extends BaseController {

    @Autowired
    CreativePublishService creativePublishService;


    @Autowired
    ClassificationService classificationService;


    @Autowired
    LabelService labelService;

    @PostMapping("/collect")
    @ApiOperation("文创活动信息发布")
    public AjaxResult collect(@RequestBody CreativePublish creativePublish) {
        creativePublishService.insert(creativePublish);
        return success();
    }

    @GetMapping("/creative")
    @ApiOperation("文创活动信息展示")
    public TableDataInfo show(@ApiParam(value = "标题") @RequestParam(value = "title",required = false) String title,
                              @ApiParam(value = "类型id") @RequestParam(value = "categoryId",required = false) int categoryId,
                              @ApiParam(value = "标签id") @RequestParam(value = "labelId",required = false) int labelId,
                              @ApiParam(value = "开始日期") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginningDate,
                              @ApiParam(value = "截至日期") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endingDate

    ) {
        startPage();
        List<CreativePublish> creativePublishList = creativePublishService.list(title, categoryId, labelId,beginningDate, endingDate);
        return getDataTable(creativePublishList);
    }


    @PutMapping("/update")
    @ApiOperation("文创活动信息修改")
    public AjaxResult update(@RequestBody CreativePublish creativePublish) {
        creativePublishService.update(creativePublish);
        return success();
    }


    @DeleteMapping("/delete")
    @ApiOperation("文创活动信息删除")
    public AjaxResult delete(@ApiParam(value = "id") @RequestParam(value = "id") int id) {
        creativePublishService.delete(id);
        return success();
    }



    @PostMapping("/type/add")
    @ApiOperation("新增作品分类")
    public AjaxResult addType(@RequestBody Classification classification) {
        classificationService.insert(classification);
        return success();
    }

    @GetMapping("/type/list")
    @ApiOperation("作品分类下拉选展示")
    public AjaxResult typeList() {
        List<Classification> list = classificationService.list();
        return success(classificationService.buildDeptTree(list));
    }

    @PutMapping("/type/update")
    @ApiOperation("修改作品分类")
    public AjaxResult updateType(@RequestBody Classification classification) {
        classificationService.update(classification);
        return success();
    }

    @DeleteMapping("/type/delete")
    @ApiOperation("删除作品分类")
    public AjaxResult deleteType(@ApiParam(value = "id") @RequestParam(value = "id") int id){
        classificationService.delete(id);
        return success();
    }

    @PostMapping("/label/add")
    @ApiOperation("新增作品标签")
    public AjaxResult addLabel(@RequestBody Label label) {
        labelService.insert(label);
        return success();
    }

    @GetMapping("/label/list")
    @ApiOperation("展示标签")
    public TableDataInfo labelList() {
        startPage();
        List<Label> list = labelService.list();
        return getDataTable(list);
    }

    @PutMapping("/label/update")
    @ApiOperation("修改标签")
    public AjaxResult updateLabel(@RequestBody Label label) {
        labelService.update(label);
        return success();
    }


    @DeleteMapping("/label/delete")
    @ApiOperation("删除标签")
    public AjaxResult deleteLabel(@ApiParam(value = "id") @RequestParam(value = "id",required = false) int id){
        labelService.delete(id);
        return success();
    }

}
